package  ${genConfig.packageName}.${genConfig.moduleName}.api.controller.v1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ray.ba.starter.web.api.ResponseData;
import com.ray.ba.starter.web.api.ResponsePage;
import ${genConfig.packageName}.${genConfig.moduleName}.infra.entity.${tableEntity.className};
import ${genConfig.packageName}.${genConfig.moduleName}.app.service.${tableEntity.className}Service;
import ${genConfig.packageName}.${genConfig.moduleName}.app.dto.${tableEntity.className}Dto;
import ${genConfig.packageName}.${genConfig.moduleName}.app.convertor.${tableEntity.className}Convertor;

/**
* <p>
*    ${tableEntity.comments}
* </p>
*
* @author: ${genConfig.author}
* @date: Created in ${datetime}
* @copyright: Copyright (c) ${year}
* @version: v1.0
* @modified: ${genConfig.author}
*/
@RestController
@RequestMapping("/v1/${tableEntity.lowerClassName}")
@AllArgsConstructor
public class ${tableEntity.className}Controller {

    private final ${tableEntity.className}Service ${tableEntity.lowerClassName}Service;
    private final ${tableEntity.className}Convertor ${tableEntity.lowerClassName}Convertor;



    @GetMapping
    public ResponseData<ResponsePage<${tableEntity.className}Dto>> list(${tableEntity.className}Dto dto,
                                                        @RequestParam(required = false, defaultValue = "0") int pageNum,
                                                        @RequestParam(required = false, defaultValue = "10") int pageSize) {
        ${tableEntity.className} ${tableEntity.lowerClassName} = ${tableEntity.lowerClassName}Convertor.toEntity(dto);
        List<${tableEntity.className}> ${tableEntity.lowerClassName}List = ${tableEntity.lowerClassName}Service.findBy(${tableEntity.lowerClassName}, pageNum, pageSize);
        return ResponseData.success(ResponsePage.restPage(${tableEntity.lowerClassName}Convertor.toDto(${tableEntity.lowerClassName}List)));
    }




    @PostMapping
    public ResponseData<${tableEntity.className}Dto> create(@Validated @RequestBody ${tableEntity.className}Dto dto) {
        ${tableEntity.className} ${tableEntity.lowerClassName} = ${tableEntity.lowerClassName}Convertor.toEntity(dto);
        ${tableEntity.lowerClassName}Service.insert(${tableEntity.lowerClassName});
        return  ResponseData.success(${tableEntity.lowerClassName}Convertor.toDto(secUserDO));
    }

    @PutMapping
    public ResponseData<${tableEntity.className}Dto> update(@RequestBody ${tableEntity.className}Dto dto) {
            ${tableEntity.className} ${tableEntity.lowerClassName} = ${tableEntity.lowerClassName}Convertor.toEntity(dto);
            ${tableEntity.lowerClassName}Service.update(${tableEntity.lowerClassName});
        return  ResponseData.success(${tableEntity.lowerClassName}Convertor.toDto(${tableEntity.lowerClassName}));
    }

    @DeleteMapping
    public ResponseData delete(@RequestBody Set<Long> ids) {
        ${tableEntity.lowerClassName}Service.deleteByIds(ids);
        return  ResponseData.success();
    }

}